package xyz.comfyz.web.commons.security.support;


import xyz.comfyz.web.commons.security.model.Authentication;

/**
 * @author :    comfy
 * @date :      2018-05-12 16:04:49
 * @since :     1.8
 * <p>
 * 上下文，提供 token和用户Authentication
 */
public abstract class SecurityContext {

    private final static ThreadLocal<String> token = new ThreadLocal<>();
    private final static ThreadLocal<Authentication> authentication = new ThreadLocal<>();

    public static String token() {
        return token.get();
    }

    public static Authentication authentication() {
        return authentication.get();
    }

    public static void set(String token) {
        SecurityContext.token.set(token);
    }

    public static void set(Authentication token) {
        authentication.set(token);
    }

    public static void clear() {
        token.remove();
        authentication.remove();
    }
}
